package com.eleadmin.ocean.controller;

import com.eleadmin.common.core.web.*;
import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.ocean.entity.OceanBulkCargoAddress;
import com.eleadmin.ocean.service.OceanBulkCargoAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 *
 * 海运散货地址库
 * @author : Doman
 * @date : 2023-10-17 15:55:16
 * @version ：1.0
 */

@Api(tags = "海运散货地址库")
@RestController
@RequestMapping("/api/ocean/oceanBulkCargoAddress")
public class OceanBulkCargoAddressController extends BaseController {

    @Autowired
    private OceanBulkCargoAddressService oceanBulkCargoAddressService;

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargoAddress:list')")
    //@ApiOperation("分页查询海运散货地址库")
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, OceanBulkCargoAddress oceanBulkCargoAddress) throws Exception{
        return oceanBulkCargoAddressService.list(page, oceanBulkCargoAddress, getLoginUser());
    }

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargoAddress:list')")
    //@ApiOperation("查询全部海运散货地址库")
    @GetMapping()
    public JsonResult list(OceanBulkCargoAddress oceanBulkCargoAddress){
        return oceanBulkCargoAddressService.list(oceanBulkCargoAddress, getLoginUser());
    }

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargoAddress:list')")
    @ApiOperation("返回海运散货地址库select列表")
    @GetMapping("listSel")
    public JsonResult listSel(OceanBulkCargoAddress oceanBulkCargoAddress){
        return oceanBulkCargoAddressService.listSel(oceanBulkCargoAddress, getLoginUser());
    }

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargoAddress:list')")
    //@ApiOperation("根据id查询海运散货地址库")
    @GetMapping("/{id}")
    public JsonResult get(@PathVariable("id") String id) {
        return oceanBulkCargoAddressService.getById(id);
    }


    @PreAuthorize("hasAuthority('ocean:oceanBulkCargoAddress:save')")
    @OperationLog
    @ApiOperation(value ="添加海运散货地址库")
    @PostMapping()
    public JsonResult save(@RequestBody OceanBulkCargoAddress oceanBulkCargoAddress) {
        try {
            return oceanBulkCargoAddressService.save(oceanBulkCargoAddress, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }

    }

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargoAddress:update')")
    @OperationLog
    @ApiOperation(value ="修改海运散货地址库")
    @PutMapping()
    public JsonResult update(@RequestBody OceanBulkCargoAddress oceanBulkCargoAddress) {
        try {
            return oceanBulkCargoAddressService.update(oceanBulkCargoAddress, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('ocean:oceanBulkCargoAddress:remove')")
    @OperationLog
    @ApiOperation(value ="删除海运散货地址库")
    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable("id") String id) {
        try {
            return oceanBulkCargoAddressService.remove(id, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

}
